/*!
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *
 *    Author: flareguner
 *    E-Mail: flareguner@gmail.com
 *    Years: 2010-2011
 */


#include "exceptionsconfig.h"
#include "src/platform.h"
#include <QtCore/QEvent>
#include <QtCore/QSettings>
#include <QtGui/QApplication>
#include <QtGui/QLayout>
#include <QtGui/QCheckBox>
#include <QtGui/QFrame>


//defaults
const bool
ExceptionsConfig::m_default_enabled = false,
ExceptionsConfig::m_default_case_sensetive = false;



ExceptionsConfig::ExceptionsConfig(QWidget *parent) :
    QWidget(parent)
{
    createUi();    changeEvent(new QEvent(QEvent::LanguageChange));


    connect(enableExceptionsCheckBox, SIGNAL(toggled(bool)),caseSensetiveFrame, SLOT(setEnabled(bool)));
    read();
}

ExceptionsConfig::~ExceptionsConfig() {
    delete enableExceptionsCheckBox;
    delete caseSensetiveCheckBox;
    delete caseSensetiveFrame;
//    delete frameLayout; TODO: FIX THIC KRAKH FUck

    delete mainLayout;
}

void ExceptionsConfig::save() {
    QSettings s(Platform::getOrganizationName(), Platform::getApplicationName());
    s.beginGroup("Exceptions");
    s.setValue("enabled", enableExceptionsCheckBox->isChecked());
    s.setValue("cs", caseSensetiveCheckBox->isChecked());
    s.endGroup();
}

void ExceptionsConfig::read() {
    QSettings s(Platform::getOrganizationName(), Platform::getApplicationName());
    s.beginGroup("Exceptions");
    enableExceptionsCheckBox->setChecked(s.value("enabled", m_default_enabled).toBool());
    caseSensetiveCheckBox->setChecked(s.value("cs", m_default_case_sensetive).toBool());
    s.endGroup();
}

void ExceptionsConfig::truncate() {
    enableExceptionsCheckBox->setChecked(m_default_enabled);
    caseSensetiveCheckBox->setChecked(m_default_case_sensetive);
}


bool ExceptionsConfig::getExceptionsEnabled() const {
    return enableExceptionsCheckBox->isChecked();
}

bool ExceptionsConfig::getExpectionsCaseSensetive() const {
    return caseSensetiveCheckBox->isChecked();
}

void ExceptionsConfig::changeEvent(QEvent *e) {
    if(e->type() == QEvent::LanguageChange) {
	enableExceptionsCheckBox->setText(QApplication::tr("Enable"));
	caseSensetiveCheckBox->setText(QApplication::tr("Case Sensetive"));
    }
}

void ExceptionsConfig::createUi() {
    enableExceptionsCheckBox = new QCheckBox(this);
    caseSensetiveCheckBox = new QCheckBox(this);

    caseSensetiveFrame = new QFrame(this);

    frameLayout = new QHBoxLayout;
    mainLayout = new QVBoxLayout;

    frameLayout->addWidget(caseSensetiveCheckBox);
    frameLayout->setContentsMargins(14,4,4,4);
    caseSensetiveFrame->setLayout(frameLayout);

    mainLayout->addWidget(enableExceptionsCheckBox);
    mainLayout->addWidget(caseSensetiveFrame);
    mainLayout->addStretch();

    this->setLayout(mainLayout);
}
